package com.mg.yygh.hosp.controller.api;

import com.mg.yygh.common.result.Result;
import com.mg.yygh.hosp.service.DepartmentService;
import com.mg.yygh.hosp.service.HospitalService;
import com.mg.yygh.hosp.service.HospitalSetService;
import com.mg.yygh.hosp.service.ScheduleService;
import com.mg.yygh.model.hosp.Hospital;
import com.mg.yygh.model.hosp.HospitalSet;
import com.mg.yygh.model.hosp.Schedule;
import com.mg.yygh.vo.hosp.DepartmentVo;
import com.mg.yygh.vo.hosp.HospitalQueryVo;
import com.mg.yygh.vo.hosp.ScheduleOrderVo;
import com.mg.yygh.vo.hosp.ScheduleQueryVo;
import com.mg.yygh.vo.order.SignInfoVo;
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.swing.plaf.synth.SynthOptionPaneUI;
import java.util.List;
import java.util.Map;

/**
 * @author M_Dragon
 * @date 2022/9/5/005 23:45
 */
@RestController
@Api(tags = "挂号平台信息展示")
@RequestMapping("/api/hosp/hospital/")
public class HospitalApiController {

    @Autowired
    private HospitalService hospitalService;

    @Autowired
    private HospitalSetService hospitalSetService;

    @Autowired
    private DepartmentService departmentService;

    @Autowired
    private ScheduleService scheduleService;

    @ApiOperation("分页查询医院列表")
    @GetMapping("findHospList/{page}/{limit}")
    public Result findHospList(@PathVariable("page") Integer page,
                               @PathVariable("limit") Integer limit,
                               HospitalQueryVo hospitalQueryVo) {
        Page<Hospital> hospitals = hospitalService.getPage(page, limit, hospitalQueryVo);
        return Result.ok(hospitals);
    }

    @ApiOperation("根据医院名称模糊查询医院列表")
    @GetMapping("findByHosname/{hosname}")
    public Result findByHosname(@PathVariable("hosname") String hosname) {
        List<Hospital> hospitalList = hospitalService.findByHosname(hosname);
        return Result.ok(hospitalList);
    }

    @ApiOperation("查询所有科室名列表")
    @GetMapping("getDepartment/{hoscode}")
    public Result getDepartment(@PathVariable("hoscode") String hoscode) {
        List<DepartmentVo> list = departmentService.getDeptList(hoscode);
        return Result.ok(list);
    }

    @ApiOperation("医院预约挂号详情")
    @GetMapping("findHospDetail/{hoscode}")
    public Result findHospDetail(@PathVariable("hoscode") String hoscode) {
        Map<String, Object> map = hospitalService.item(hoscode);
        return Result.ok(map);
    }

    @ApiOperation("获取可预约排班数据")
    @GetMapping("auth/getBookingScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
    public Result getBookingSchedule(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable Integer page,
            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @PathVariable Integer limit,
            @ApiParam(name = "hoscode", value = "医院code", required = true)
            @PathVariable String hoscode,
            @ApiParam(name = "depcode", value = "科室code", required = true)
            @PathVariable String depcode
    ) {
        return Result.ok(scheduleService.getBookingScheduleRule(page, limit, hoscode, depcode));
    }

    @ApiOperation(value = "获取排班数据")
    @GetMapping("auth/findScheduleList/{hoscode}/{depcode}/{workDate}")
    public Result findScheduleList(@ApiParam(name = "hoscode", value = "医院code", required = true)
                                   @PathVariable String hoscode,
                                   @ApiParam(name = "depcode", value = "科室code", required = true)
                                   @PathVariable String depcode,
                                   @ApiParam(name = "workDate", value = "排班日期", required = true)
                                   @PathVariable String workDate) {
        return Result.ok(scheduleService.getDetailSchedule(hoscode, depcode, workDate));
    }

    @ApiOperation("根据排班id获取排班数据")
    @GetMapping("getSchedule/{hosScheduleId}")
    public Result getSchedule(@ApiParam(name = "hosScheduleId",value = "排班id",required = true)
                              @PathVariable String hosScheduleId){
        Schedule schedule = scheduleService.getById(hosScheduleId);

        return Result.ok(schedule);
    }

    @ApiOperation("内部调用：根据排班id获取预约下单数据")
    @GetMapping("inner/getScheduleOrderVo/{scheduleId}")
    public ScheduleOrderVo getScheduleOrderVo(@PathVariable("scheduleId") String scheduleId){
        return scheduleService.getScheduleOrderVo(scheduleId);
    }

    @ApiOperation("内部调用：获取医院签名信息")
    @GetMapping("inner/getSignInfoVo/{hoscode}")
    public SignInfoVo getSignInfoVo(@PathVariable("hoscode") String hoscode) {
        return hospitalSetService.getSignInfoVo(hoscode);
    }

}
